package com.asa.shishu;
/**
 * 
 * 厄米多项式
 * @author Administrator
 *
 */

import com.asa.HanShu;

public class Hermite {

	
	

	//函数原型
	//Hn（x）={ n<=0;  1   
	//	     { n=1;   2*x
	//	     { n>=2;  2*x*Hn-1(x)-2(n-1)Hn-2(x)
	private static double  Hermite(int n,double x)
	{
		if (n <= 0)
			return 1;
		else if (n == 1)
			return 2 * x;
		else
			return 2 * x*Hermite(n - 1, x) - 2 * (n - 1)*Hermite(n - 2, x);
	}


	public static HanShu Hermite_Hanshu(final int n) {
		
		HanShu hanShu = new HanShu() {
			
			@Override
			public double hanshu(double t, double x) {
				// TODO Auto-generated method stub
				return 0;
			}
			
			@Override
			public double hanshu(double x) {
				// TODO Auto-generated method stub
				return Hermite(n, x);
			}
		};
		
		
		return hanShu;
	}
	
	
	public static void main(String[] args) {
		HanShu hermite_Hanshu = Hermite_Hanshu(2);
		
		System.out.println(hermite_Hanshu.hanshu(2));
	}
	
	
	
	
	
	
}
